package guiLayer;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import controllerLayer.PasswordController;

public class AdminGUI extends JFrame {

	private JPanel contentPane;
//	private String password = "password";
	private String user = "user-name";
	private JTextField textField;
	private JTextField textField_1;
	private JPanel panel = new JPanel();
	private JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AdminGUI frame = new AdminGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public AdminGUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		panel.setLayout(null);
		contentPane.add(panel, BorderLayout.CENTER);
		

		
		makeLogin();
	}
	
private void makeLogin(){
		
		JLabel lblNewLabel = new JLabel("Login");
		lblNewLabel.setBounds(10, 11, 46, 14);
		panel.add(lblNewLabel);
		
		
		textField_1 = new JPasswordField();
		textField_1.setBounds(10, 59, 86, 20);
		panel.add(textField_1);
		textField_1.setColumns(10);
		

		textField = new JTextField(user);
		textField.setBounds(10, 28, 86, 20);
		panel.add(textField);
		textField.setColumns(10);
		
		JButton btnLogin = new JButton("log ind");
		btnLogin.setBounds(10, 90, 86, 23);
		panel.add(btnLogin);
		btnLogin.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(!textField.getText().equals(user)
						&& textField.getText().isEmpty() && textField_1.getText().isEmpty()){
					JOptionPane.showMessageDialog(rootPane, "udfyld login formular");
				}
				else if(!textField.getText().equals("admin")){
					JOptionPane.showMessageDialog(rootPane, "fejl");
				}
				else
				{
					PasswordController psCtr = new PasswordController();
					if(psCtr.checkPass(textField.getText(),textField_1.getText())){
						
						panel.removeAll();
						makeJTabbedPane();
						contentPane.revalidate();
						contentPane.repaint();
					}
				}
			}
			
		});
		
		
		
		
	}

	public JPanel makeAll(){
		return contentPane;
	}
	
	private void makeJTabbedPane(){
		
		
		
		tabbedPane.setBounds(10, 11, 1024, 600);
		
		
		makePersonGUI();
		panel.add(tabbedPane);
		
		
	}
	
	private void makePersonGUI(){
		PersonGUI pe = new PersonGUI();
		
		JPanel peP = pe.makeAll();
		
		tabbedPane.addTab("Person", peP);
	}
}
